﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Character.Jarily { 
    public class ReusableCode : MonoBehaviour
    {
        public static void electricity(Transform[] m_point,bool Ring)
        {
            List<RaycastHit2D> x_point = new List<RaycastHit2D>();
            RaycastHit2D[] _point;

            for (int i = 1; i <= m_point.Length; i++)
                if (i < m_point.Length)
                { 
                    x_point.Add(Physics2D.CapsuleCast(m_point[i - 1].position, Vector2.right * 0.5f, CapsuleDirection2D.Horizontal, 0.0f, m_point[i].position - m_point[i - 1].position, (m_point[i].position - m_point[i - 1].position).sqrMagnitude));
                }
                else if (i == m_point.Length && Ring)
                    x_point.Add(Physics2D.CapsuleCast(m_point[i - 1].position, Vector2.right * 0.5f, CapsuleDirection2D.Horizontal, 0.0f, m_point[0].position - m_point[i - 1].position, (m_point[0].position - m_point[i - 1].position).sqrMagnitude));

            _point = x_point.ToArray();

            foreach (RaycastHit2D x in _point)
            {
                if (x.collider.gameObject.GetComponent<Chain>().m_meterial == Meterial.iron)
                {
                    electricity(x.collider.gameObject.GetComponent<Chain>().m_point, x.collider.gameObject.GetComponent<Chain>().Ring);
                }
                if (x.collider.gameObject.layer == LayerMask.NameToLayer("Enemy"))
                {
                    Destroy(x.collider.gameObject);
                    Debug.Log("击杀敌人");
                }
            }

            Show();
        }
        public static void Show()
        {
            //...特效
        }
    }
}
